{include file="public/header" /}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.css"}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.js"}
    {load href="__CSS__video-js.min.css"}
    {load href="__JS__video.min.js"}
<style>
    #des, #des input {
        width: 40px;
        text-align: center;
    }

    #id {
        width: 78px;
    }

    .bs-checkbox {
        width: 36px;
        height: 40px
    }

    .fixed-table-toolbar .columns, .fixed-table-toolbar .search {
        margin-left: 0px;
        margin-top: 0px
    }

    #title span {
        float: right;
        margin-left: 3.333px;
    }

    .search {
        margin-bottom: 0px !important;
    }

    .asdlkjasd {
        background: #1ab394;
        color: #fff
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content {:config('adminClass.main')}">
    <div class="ibox float-e-margins">
        {include file="public/tophead"}
        {include file="public/top" /}
        <div class="ibox-content">
            {include file="public/topsection"}
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div class="fixed-table-toolbar loadClick">
                        <a class="btn btn-default btn-outline {present name='shenhe'}{else /}asdlkjasd{/present}" href="{:url('dymanic')}{present name='type'}/type/{$type}{/present}">全部</a>
                        <a class="btn btn-default btn-outline {present name='shenhe'}{eq name='shenhe' value='1'}asdlkjasd{/eq}{else /}{/present}" href="{:url('dymanic',['shenhe'=>1])}{present name='type'}/type/{$type}{/present}">通过</a>
                        <a class="btn btn-default btn-outline {present name='shenhe'}{eq name='shenhe' value='0'}asdlkjasd{/eq}{/present}" href="{:url('dymanic',['shenhe'=>0])}{present name='type'}/type/{$type}{/present}">审核</a>
                        <a class="btn btn-default btn-outline {present name='shenhe'}{eq name='shenhe' value='-1'}asdlkjasd{/eq}{/present}" href="{:url('dymanic',['shenhe'=>-1])}{present name='type'}/type/{$type}{/present}">拒绝</a>

                        <!-- <a style="margin-left: 50px;" class="btn btn-default btn-outline {notpresent name='addway'}asdlkjasd{/notpresent}" href="{:url('dymanic')}{present name='shenhe'}/shenhe/{$shenhe}{/present}{present name='class'}/class/{$class}{/present}">全部</a>
                        <a class="btn btn-default btn-outline {present name='addway'}{eq name='addway' value='2'}asdlkjasd{/eq}{/present}" href="{:url('dymanic',['addway'=>2])}{present name='shenhe'}/shenhe/{$shenhe}{/present}{present name='class'}/class/{$class}{/present}">用户发布</a>
                        <a class="btn btn-default btn-outline {present name='addway'}{eq name='addway' value='0'}asdlkjasd{/eq}{/present}" href="{:url('dymanic',['addway'=>0])}{present name='shenhe'}/shenhe/{$shenhe}{/present}{present name='class'}/class/{$class}{/present}">平台发布</a> -->
                    </div>
                    <div class="fixed-table-toolbar loadClick">
                        <form  method="get" action="">
                            <div class="pull-left search">
                                <!--    <div class="columns columns-right btn-group pull-left" >
                                       <select class="form-control" name="where">
                                           <option value="">全部</option>
                                           <option value="id">文章ID</option>
                                       </select>
                                   </div> -->
                                <div class="columns columns-right btn-group pull-left" >
                                    <div class="columns columns-right btn-group pull-left" >
                                        <select class="form-control" name="search_typeid">
                                            <option value="userid">用户id</option>
                                            <option value="phone" {eq name="search_typeid" value="phone" }selected{/eq}>用户手机号</option>
                                            <option value="dy_id" {eq name="search_typeid" value="dy_id" }selected{/eq}>动态id</option>
                                            <option value="title"  {eq name="search_typeid" value="title" }selected{/eq}>标题/内容</option>
                                            {php}
                                            if(input('?param.search_typeid')){
                                            $typeidname=input('param.search_typeid');
                                            }else{
                                            $typeidname='';
                                            }
                                            {/php}
                                            {$typeidname}
                                        </select>
                                    </div>
                                </div>
                                {php}
                                if(input('?param.search_typeid') || input('?param.search_name')){
                                {/php}
                                <div class="pull-right search">
                                    <a class="btn btn-w-m btn-link" href="{:url('dymanic')}">返回管理</a>
                                </div>{php}
                                }
                                {/php}
                                <div class="pull-right search">
                                    <button style="border-radius:0px; border:1px solid #e5e6e7; border-left:0px" class="btn btn-default btn-outline" id="search-btn" type="submit">搜索</button>
                                </div>
                                <div class="pull-right search">
                                    <input class="form-control input-outline" id="filter" type="text"
                                           {php}
                                           if(input('?param.search_name')){
                                    if(input('param.search_name')){
                                    echo "value='".input('search_name')."'";
                                    }
                                    }
                                    {/php}
                                    name="search_name" placeholder="输入标题搜索">
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="example">
                        <form class="form-horizontal" method="post">
                            <table
                                data-toggle="table"
                                data-show-columns="true"
                                data-show-columns-toggle-all="true"
                            >
                                <thead>
                                <tr>
                                    <th class="bs-checkbox" data-switchable="false"><input type="checkbox" id="delidAll"></th>
                                    <th data-align="center">ID</th>
                                        {if condition="$class == 2"}
                                    <th data-align="center">分类</th>
                                        {/if}
                                    <th data-align="center">创建人</th>
                                    <th data-align="center">用户ID</th>
                                    <th>内容</th>
                                    <th>图片/视频</th>
                                    <!-- <th data-align="center">发布城市</th> -->
                                    <th data-align="center">点赞数量</th>
                                    <!-- <th data-align="center">来源</th> -->
                                    <th data-align="center">观看权限</th>
                                    <th data-align="center">评论权限</th>
                                    <th data-align="center">创建时间</th>
                                    <th data-align="center">审核时间</th>
                                    <th data-align="center">审核管理员</th>
                                    <th data-align="center">状态</th>
                                    <th data-align="center">管理</th>
                                </tr>
                                </thead>
                                <tbody id="form">
                                    {php}
                                    $entertainments = ['娱乐','分享','交友','相亲'];
                                    {/php}
                                {volist name="data" id="v" key="k"}
                                <tr id="id{$v.dy_id}" class="class">
                                    <td id="delid" ><input name="delAll[]" type="checkbox" value="{$v.dy_id}"></td>
                                    <td id="id">{$v.dy_id}</td>
                                        {if condition="$v.class == 2"}
                                    <td>
                                        <a style="color:#40BCF7"  onclick="add('{:url('categoryEdit',['id'=>$v['dy_id'],'url'=>-1])}')">{if condition="$v.name"}{$v.name}{else}设置分类{/if}</a>
                                    </td>
                                        {/if}
                                    <td >
                                        {if condition="$v.type==2"}系统{else /}
                                        <a onclick="member('{$v.userid}')" style="color:#40BCF7">{$v.username}（{$v.sex}）</a>
                                        {/if}
                                    </td>
                                    <td>
                                        {$v.id}
                                    </td>
                                    <td id="title">
                                        {if condition="$v.price > 0"}
                                        <span style="color:red;">￥{$v.price}</span>
                                        {/if}
                                        {if condition="$v.topic"}
                                        <a style="color:skyblue;" onclick="add('{:url('addDymanic',['id'=>$v.dy_id,'url'=>-1,'type'=>$v.type])}')">{$v.topic}</a>
                                        {/if}
                                        {if condition="$v.topic_experience"}
                                        <a style="color:skyblue;" onclick="add('{:url('addDymanic',['id'=>$v.dy_id,'url'=>-1,'type'=>$v.type])}')">{$v.topic_experience}</a>
                                        {/if}

                                        <a onclick="watch('{$v.dy_id}')">
                                            <?php echo $v['content']; ?>
                                        </a>


                                    </td>
                                    <td>
                                        {volist name="$v.masterimg" id="img"}
                                        {php}
                                            $imageUrl = strpos($img, 'http') === false ? '__ROOT__' . $img : $img;
                                            $escapedUrl = htmlspecialchars($imageUrl, ENT_QUOTES, 'UTF-8');
                                        {/php}
                                           
                                        {if condition="$escapedUrl"}
                                            <a href="{$escapedUrl}" target="_blank" onclick="lookBigImg('{$escapedUrl}')">
                                                <img style="width:80px;height:80px;" src="{$escapedUrl}"/>
                                            </a>
                                         {/if}
                                        <!--<a href="{:strpos($img, 'http')===false?'__ROOT__':''}{$img}" target="_blank">-->
                                        <!--    <img style="width:80px;height:80px;" src="{:strpos($img, 'http')===false?'__ROOT__':''}{$img}"/>-->
                                        <!--</a>-->
                                        {/volist}
                                       <!-- {if condition="$v.video"}
                                        <video id="video{$k}" class="video-js vjs-default-skin" controls preload="auto"></video>

                                        {/if} -->
										 {if condition="$v.video && !empty($v.video)"}
										        <?php
										        $videoUrl = strpos($v['video'], 'http') === false ? '__ROOT__' . $v['video'] : $v['video'];
										        $isM3u8 = strpos($v['video'], 'm3u8') !== false;
										        $videoType = $isM3u8 ? 'application/x-mpegURL' : 'video/mp4';
										        $escapedVideoUrl = htmlspecialchars($videoUrl, ENT_QUOTES, 'UTF-8');
										        $escapedVideoType = htmlspecialchars($videoType, ENT_QUOTES, 'UTF-8');
										        ?>
										        <video 
										            id="video{$k}" 
										            class="video-js vjs-default-skin" 
										            preload="auto"
													style="width: 300px !important;height: 150px !important;"
										            onclick="event.preventDefault();openVideoPopup('<?php echo $escapedVideoUrl; ?>', '<?php echo $escapedVideoType; ?>')"
										        >
										            <source src="<?php echo $escapedVideoUrl; ?>" type="<?php echo $escapedVideoType; ?>">
										        </video>
										    {/if}
										
										
										
										
										
										
										
										
										
										
                                    </td>
                                   <!--  <td>
                                        {$v.citys}
                                    </td> -->
                                    <td>
                                        {$v.thumbsup}
                                    </td>
                                    <!-- <td>
                                        <span style="color:red;">({$v.addway==0?'平台':'用户'})</span>
                                        {$v.source_type_text}
                                    </td> -->
                                    <td>
                                        <select onchange="setDyLimit('see_limit', this.value, '{$v.dy_id}')">
                                            <option value="0" {eq name="$v.see_limit" value="0"}selected{/eq}>未开放</option>
                                            <option value="1" {eq name="$v.see_limit" value="1"}selected{/eq}>女性专看</option>
                                            <option value="2" {eq name="$v.see_limit" value="2"}selected{/eq}>男性专看</option>
                                            <option value="3" {eq name="$v.see_limit" value="3"}selected{/eq}>均可</option>
                                        </select>
                                    </td>
                                    <td>
                                        <select onchange="setDyLimit('ping_limit', this.value, '{$v.dy_id}')">
                                            <option value="0" {eq name="$v.ping_limit" value="0"}selected{/eq}>未开放</option>
                                            <option value="1" {eq name="$v.ping_limit" value="1"}selected{/eq}>女性可评论</option>
                                            <option value="2" {eq name="$v.ping_limit" value="2"}selected{/eq}>男性可评论</option>
                                            <option value="3" {eq name="$v.ping_limit" value="3"}selected{/eq}>均可</option>
                                        </select>
                                    </td>
                                    <td>
                                        <span>{$v.addtime}</span>
                                    </td>
                                    <td>
                                        <span>{neq name="$v.shenhe_time" value="0"}{:date('Y-m-d H:i:s', $v.shenhe_time)}{/neq}</span>
                                    </td>
                                    <td>
                                        <span>{:_getAdminName($v.admin_id)}</span>
                                    </td>
                                    <td id="hide{$v.dy_id}">{if condition="$v.shenhe eq '0'"}<span style="color: #ed5565">审 核</span>{elseif condition="$v.shenhe eq '1'" /}<span style="color: #1ab394">通 过</span>{elseif condition="$v.shenhe eq '-1'" /}<span style="color: #ed5565">拒 绝</span> {$v.reason}{/if}</td>
                                    <td>
                                        <div class="btn-group">
                                            <div data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">操作 <span class="caret"></span>
                                            </div>
                                            <ul class="dropdown-menu">
                                                <li><a onclick="add('{:url('addDymanic',['id'=>$v.dy_id,'url'=>-1,'type'=>$v.type])}')">修改</a></li>
                                                <li class="divider"></li>
                                                <li><a onclick="add('{:url('comment',['id'=>$v.dy_id,'url'=>-1])}')">评论</a></li>
                                                <li class="divider"></li>
                                                {switch name="$v.shenhe"}
                                                {case value="-1"}
                                                <li><a onClick="shenhe({$v.dy_id},'0')">审核</a></li>
                                                <li><a onClick="shenhe({$v.dy_id},'1')"><span style="color: #1ab394; ">通过</span></a></li>
                                                {/case}
                                                {case value="0"}
                                                <li><a onClick="shenhe({$v.dy_id},'1')"><span style="color: #1ab394; ">通过</span></a></li>
                                                <li><a onClick="shenhe({$v.dy_id},'-1')"><span style="color: #ed5565; ">拒绝</span></a></li>
                                                {/case}
                                                {case value="1"}
                                                <li><a onClick="shenhe({$v.dy_id},'-1')"><span style="color: #ed5565; ">拒绝</span></a></li>
                                                <li><a onClick="shenhe({$v.dy_id},'0')">审核</a></li>
                                                {/case}
                                                {/switch}
                                                <li class="divider"></li>
                                                <li><a onclick="del('{$v.dy_id}')">删除</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>

                                </tr>
                                {/volist}
                                </tbody>

                            </table>
                        </form>
                    </div>
                </div>
            </div>
            <hr>
            <div class="row row-lg">
                <div class="col-sm-6 loadClick">
                    <a  class="btn btn-outline btn-default" onclick="alla(1)">
                        批量通过
                    </a>
                    <a  class="btn btn-outline btn-default" onclick="alla(-1)">
                        批量拒绝
                    </a>
                    <a  class="btn btn-outline btn-default" onclick="alla(0)">
                        批量审核
                    </a>
                    <a class="btn btn-outline btn-default" onclick="alla('del')">
                        批量删除
                    </a>
                </div>
                <div class="col-sm-6 pages">{$page}</div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
    
    $(document).ready(function(){
        $('#desAll').click(function(){
            var des=$(".form-horizontal").serialize();
            ajaxFun("post",'{:url('article/desAll')}',des,'json',function(ret){
                if(ret){
                    if(ret.ret){
                        self.location.reload();
                    }else{
                        layer.msg(ret.err)
                    }
                }else{
                    swal_msg("错误",ret,"error");
                }
            })
        })

        $('#delidAll').click(function(){
            $('input[type=checkbox]').each(function(){
                var self=$(this);
                if(!self.prop('checked')){
                    self.prop('checked',true);
                }else{
                    self.prop('checked',false);
                }
            });
        })
    });
    function del(id){
        swal_del(id,"{:url('del')}")
    }
    function alla(types){
        var all=$(".form-horizontal").serialize();
        var alls=$(".form-horizontal").serializeArray();
        console.log(JSON.stringify(alls))

        ajaxFun("post",'{:url('article/shenheAll')}?type='+types,all,'json',function(ret){

            if(ret){
                var text
                switch(types)
                {
                    case -1:
                        text = '<span class="btn btn-primary btn-xs" style="background-color: #414141;border-color:#414141">拒 绝</span>';
                        break;
                    case 0:
                        text = '<span class="btn btn-default btn-xs">审 核</span>';
                        break;
                    case 1:
                        text = '<span class="btn btn-primary btn-xs">通 过</span>';
                        break;
                    case 2:
                        text = '<span class="btn btn-primary btn-xs">通 过</span>';
                        break;
                }
                for(var i=0;i<alls.length;i++){
                    if(types=='del'){
                        $('#id'+alls[i]['value']).remove();
                    }else{
                        $('#hide'+alls[i]['value']).html(text);
                    }
                }
                layer.closeAll('loading'); 
                swal_msg('操作成功')
            }
        })

    }
    function watch(id) {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("article/watch")}?id='+id
        });


        });
    }
    var reasons = JSON.parse('{$rejects}');
    var reasonHtml = '';
    reasons.forEach(item=>{
        reasonHtml += `<div style="margin:5px 10px;cursor: pointer;" onclick="inputEnter('${item.reason}')">${item.reason}</div>`
    })
    function inputEnter(v) {
        $('#extraInput').val(v)
    }
  function shenhe(id,value){
    if(value == -1){
        var extraContent = `<div>
                                <textarea class="layui-layer-input" id="extraInput"></textarea>
                                <div style="display:flex;flex-wrap:wrap;padding-top:20px;">${reasonHtml}</div>
                            </div>`;

      layer.prompt({
        formType: 2,
        value: '',
        title: '请输入拒绝原因',
        content: extraContent, // 额外的内容
        area: ['500px', '400px'] //自定义文本域宽高
      }, function(reason, index, elem){
        shenheAction(id, value, reason)
        layer.close(index);
      });
    } else {
      shenheAction(id,value)
    }
  }
  function shenheAction(id,value,reason='') {
      ajaxFun("post","{:url('authadd')}",{id:id,shenhe:value,reason},'json',function(ret){
          if(ret){
              if(ret.ret){
                  layer.msg(ret.ret)
                  window.location.reload()
              }else{
                  layer.msg(ret.err)
              }
          }else{
              swal_msg("错误",ret,"error");
          }
      })
  }

  function setDyLimit(key, value, dy_id) {
      ajaxFun("post","{:url('setDyLimit')}",{key, value, dy_id},'json',function(ret){
          if(ret){
              if(ret.ret){
                  layer.msg(ret.ret)
              }else{
                  layer.msg(ret.err)
              }
          }else{
              swal_msg("错误",ret,"error");
          }
      })
  }

    function member(id)
    {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title :'预览',
                area: ['100%', '100%'],
                type: 2,
                content: '{:url("member/index")}?search=id&name='+id
            });
        });
    }
	
	
	 function openVideoPopup(src, type) {
		layui.use('layer', function(){
			const layer = layui.layer;
			layer.open({
				type: 1,
				title: '视频播放',
				area: ['60%', '70%'],
				content: `
					 <div style="display: flex; justify-content: center; align-items: center; width: 100%; height: 100%; margin: 0; padding: 0;">
						<video 
							class="video-js vjs-default-skin" 
							controls 
							preload="auto"
						    data-setup='{"fluid": false}'
						    style="width: 100%; height: 100% !important; object-fit: contain;"
						>
							<source src="${src}" type="${type}">
						</video>
					</div>
				`,
				success: function(layero, index) {
					// 初始化弹框内的视频播放器
					const popupVideo = layero.find('video')[0];
					const popupPlayer = videojs(popupVideo);
					popupPlayer.play();
				},
				end: function() {
					// 关闭弹框时停止播放
					const popupVideo = document.querySelector('.layui-layer-content video');
					if (popupVideo) {
						const popupPlayer = videojs(popupVideo);
						popupPlayer.pause();
						popupPlayer.dispose();
					}
				}
			});
		});
	}
</script>
 